package com.ahao.sdk;

import android.content.Context;

import com.ahao.sdk.ui.dialog.LoginDialog;
import com.ahao.sdk.ui.dialog.PayDialog;
import com.ahao.sdk.ui.dialog.PersonalCenterDialog;

import android.os.Handler;
import android.os.Looper;

public class AHAOPlatformUiManager {
    private static final long DEBOUNCE_DELAY = 50; // 防抖延迟时间，单位毫秒

    private static AHAOPlatformUiManager instance = new AHAOPlatformUiManager();
    private final Handler handler;

    private AHAOPlatformUiManager() {
        handler = new Handler(Looper.getMainLooper());
    }

    public static AHAOPlatformUiManager getInstance() {
        return instance;
    }

    public void showLogin(final Context context) {
        debounceAction(new Runnable() {
            @Override
            public void run() {
                new LoginDialog(context).show();
            }
        });
    }

    public void showPay(final Context context) {
        debounceAction(new Runnable() {
            @Override
            public void run() {
                new PayDialog(context).show();
            }
        });
    }

    public void showPersonalCenterDialog(final Context context) {
        debounceAction(new Runnable() {
            @Override
            public void run() {
                new PersonalCenterDialog(context).show();
            }
        });
    }

    private void debounceAction(final Runnable action) {
        handler.removeCallbacksAndMessages(null);
        handler.postDelayed(action, DEBOUNCE_DELAY);
    }
}
